package com.gzhryc.system;

import com.gzhryc.common.secruity.EncryptTools;
import org.apache.commons.lang3.StringUtils;

public class ManagerFastLoginUtils {

    public static String getLoginToken(String token){
        if(StringUtils.isNotBlank(token)) {
            Long time = System.currentTimeMillis();
            String loginToken = EncryptTools.md5(token + time);
            Long suffix = time % 10000000;
            loginToken = loginToken + suffix;
            return loginToken;
        }
        return null;
    }

    public static boolean checkLoginToken(String token,String loginToken){
        if(StringUtils.isNotBlank(token) && StringUtils.isNotBlank(loginToken) && loginToken.length() == 39){
            String suffix = loginToken.substring(32);
            String time = (System.currentTimeMillis() / 10000000) + suffix;
            String temp = EncryptTools.md5(token + time) + suffix;
            if(temp.equals(loginToken)){
                return true;
            }
        }
        return false;
    }
}
